<script type="text/javascript" >
    function set_size(){
        var size = jQuery("#result").height();
        size = size+50;
        jQuery(".pp_content").attr('style','height:'+size+'px');
    }
    jQuery(".galleryVideo a[rel^='prettyPhoto']").prettyPhoto({
            theme:'facebook',
            default_height:100,
            keyboard_shortcuts: false
        });
    stFacebookToolbox.load_tooltip();
    stFacebookToolboxcustom.on_submitform_new('#uploadObject2');
//    stFacebookToolbox.on_submitform('#uploadObject', function(data){
//       // stFacebookToolbox.loadPage('gallery_app', '', '<?php _e("Successful", $config['plugin_name']) ?>');
//    });
    stFacebookToolbox.loadUploadButton('200');
    stFacebookToolbox.loadRemoveButton();
    stFacebookToolbox.shortAction();
    function edit(id,name,facebook_id,facebook_name,flick_id){
        jQuery('.upload_field').slideDown();
        jQuery("#id").val(id);
        jQuery("#name").val(name);
        jQuery("#flick_id").val(flick_id);
        jQuery("#flick_backup").val(flick_id)
        jQuery("#facebook_id").html('');
        if(flick_id != ''){
            jQuery("#flickr").attr('checked','checked');
            jQuery("#display_flickr").slideDown();
        }
        else {
            jQuery("#flickr").removeAttr('checked');
            jQuery("#display_flickr").slideUp();
        }
        jQuery("#facebook_id").append('<option value="">Not assigned</option>');
        <?php foreach($page as $pe): ?>
                jQuery("#facebook_id").append('<option value="<?php echo $pe->pageid;?>"><?php echo $pe->pagename;?></option>');
        <?php endforeach;?>
        jQuery("#facebook_id").append('<option value="'+facebook_id+'">'+facebook_name+'</option>');
        jQuery("#facebook_id").val(facebook_id);
        jQuery("#reset_upload_file").addClass('hide');
        jQuery("#image_upload_file").attr('style','display:none');
    }
    function add_album(){
        jQuery('.upload_field').slideDown();
        jQuery("#id").val('');
        jQuery("#name").val('');
        jQuery("#flick_id").val('');
        jQuery("#flick_backup").val('');
        jQuery("#flickr").removeAttr('checked');
        jQuery("#display_flickr").hide();
        jQuery("#facebook_id").val('');
        jQuery("#facebook_id").html('');
        jQuery("#facebook_id").append('<option value="">Not assigned</option>');
        <?php foreach($page as $pe): ?>
                jQuery("#facebook_id").append('<option value="<?php echo $pe->pageid;?>"><?php echo $pe->pagename;?></option>');
        <?php endforeach;?>
        jQuery("#reset_upload_file").addClass('hide');
        jQuery("#image_upload_file").attr('style','display:none');
    }
    function set_flickr(checked){
        if(checked){
            jQuery("#display_flickr").slideDown();
            jQuery("#flick_id").val(jQuery("#flick_backup").val());
            
        }
        else {
            jQuery("#display_flickr").slideUp();
            jQuery("#flick_id").val('');
        }
    }
</script>
<style>

</style>

<div class="w100p bgl">
    <div class="w100p bgr p5b">


        <ul class="postcardAction" style="margin-left: 10px;padding-top: 15px;">
                <li>
                    <a class="button add-new-h2 anchor" onclick="add_album();">
                        Add new album
                    </a>
                </li>
            </ul>
        <div class="upload_field" style="display:none;padding-left:13px;">
                <form method="post" action="<?php echo admin_url('/admin.php?page=' . $config['plugin_name'] . '&action=' . $current_action) ?>" style="display: block;" id="uploadObject2" class="stform">
                    <ul>
                        <li>
                            <label>Name:</label>
                            <div class="required">
                                <input type="text" name="data[name]" id="name" class="required"  />
                            </div>
                                <input type="hidden" name="data[id]" id="id"  />
                            <br clear="all">
                        </li>
                        <li>
                        <label>Use picture from Flickr:</label>
                        <div>
                            <input type="checkbox" id="flickr" value="1"  onclick="set_flickr(this.checked);" />
                       </div>
                        <br clear="both" />
                        </li>
                        <li id="display_flickr" style="display:none;">
                            <label>Flickr:</label>
                            <div class="">
                                <input type="text" name="data[flick_id]" id="flick_id" class="" onkeyup="jQuery('#flick_backup').val(this.value);"  />
                                <input type="hidden" name="" id="flick_backup" class=""  />
                            </div>
                            <br clear="all">
                        </li>
                        <li>
                            <label>Facebook page:</label>
                            <div class="">
<!--                                <input type="text" name="data[facebook_id]" id="facebook_id" class="required"  />-->
                                <select name="data[facebook_id]" id="facebook_id" class="">
                                    <option value="">Not assigned</option>
                                    <?php foreach($page as $pa):?>
                                    <option value="<?php $pa->pageid;?>"><?php echo $pa->pagename;?></option>
                                    <?php endforeach;?>
                                </select>
                            </div>
                              <br clear="all">
                              <input type="button" onclick="window.open('http://www.facebook.com/add.php?api_key=<?php echo $config['galley_facebook'];?>&amp;pages=1&amp;page='+jQuery('#facebook_id').val());" value="Add gallery to facebook page" style="background-color:#3B5998;color:#FFF;font-weight: bold;border:none;cursor:pointer;margin-left:106px;">
                        </li>
                        <li>
                            <input type="submit" value="Submit">
                            <input type="button" onclick="jQuery('.upload_field').slideUp()" value="Close">
                        </li>
                    </ul>
                    <br style="clear:both;" />
                </form>
            </div>
<table class="widefat" cellspacing="0">
                <thead>
                    <tr>
                        <?php print_column_headers('stFacebookToolbox_stFacebookToolbox'); ?>
                    </tr>
                </thead>

                <tbody>
                <?php
                if (count($results) > 0) {
                    
                    $tr_class = "";
                    foreach ($results as $result) {
                         if( empty($tr_class) || $tr_class == "class='bg_gray2'"){
                            $tr_class = "class='bg_gray1'";
                        }else{
                            $tr_class = "class='bg_gray2'";
                        }
                        echo "<tr id='$result->id' $tr_class >"
                        . "<td>" . $result->id

                        . "</td>"
                        . "<td>" . $result->name
                        . "<div class=\"row-actions short_action\">"
                        . "<div onclick='edit($result->id,\"$result->name\",\"$result->facebook_id\",\"{$model->get_page($result->facebook_id)}\",\"$result->flick_id\")' style='cursor:pointer;'>Edit | </div>"
                        . "<span class='trash' short_action='delete' id='$result->id' confirm='Are you sure you want to delete this album?' style='cursor:pointer;'>Trash </span>"
                        . "</div>"
                        . "</td>"
                        . "<td>"
                        . $result->flick_id
                        . "</td>"
                        . "<td><a href='{$model->get_url($result->facebook_id)}?sk=app_".$config['galley_facebook']."' target='_blank'>" . $model->get_page($result->facebook_id)
                        . "</a></td>"
                        . "<td onclick='jQuery.prettyPhoto.loadPage(\"gallery_embed&id=$result->id\",null,null,function(){set_size();});' style='cursor:pointer;'>View</td>"
                        . "</td>"
                        
                        . "</tr>"
                        ;
                    }
                }
                ?>
                </tbody>
            </table>
            <div class="page_d">
                <?php echo $pagination?>
                <div class="cl"></div>
            </div>
    </div>
</div>